package org.example.linenumber;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import javax.annotation.Resource;

/**
 * @author zss
 * @date 2021/8/11 13:02
 * @Email:451682479@qq.com
 * @desc 字符缓冲输入流，可以获取和设置行号
 */
public class MyLineNumberReader {

    public static void main(String[] args) throws IOException {

        String path = "D:\\1My\\1BE-java\\io-stream-demo\\src\\main\\resources\\names.txt";

        BufferedReader br = new BufferedReader(new FileReader(path));

        LineNumberReader lnr = new LineNumberReader(new FileReader(path));

        String line;

        while ((line = lnr.readLine()) != null) {
            System.out.println( lnr.getLineNumber() + " : " + line);

        }

        while ((line = br.readLine()) != null) {
            System.out.println( " : " + line);

        }

        br.close();
    }

}
